/***************************************************************************
 创建者: 华磊
 开始时间: 201９.３.1３
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2018.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file ｘｘ.h
 *  功能: socket调度接口
 *
 *
 ***************************************************************************/

#ifndef SOCKETFLEETADAPTER_H
#define SOCKETFLEETADAPTER_H

#include <QObject>
#include "GeneralDefine.h"
#include <QQueue>
#include <QString>

class QTcpSocket;
class QTcpServer;
class QTimer;
class FleetService;

//请求或回应格式：0x0a(换行符\n）+headers（字符表示）+payload（字符表示）+0x0d（回车符\r）

class SocketFleetAdapter : public QObject
{
    Q_OBJECT
public:
    explicit SocketFleetAdapter(QString configFileIn,FleetService *fleetServiceIn,
                                QObject *parent = nullptr);
public:
    bool isInitialOk();
    bool isSocketOkStatus();
    bool isUseThisModule();
    int getFleetCommandLog(QQueue<QString> &fleetCommandLogOut);

private slots:
    void timeOut_slot();
    void newConnectionSlot();

signals:

private:
    int executeOneCommandAndReply(QString tmp_frame);
    int sendTrigPoseQueue();
    int monitorDi();
    int initialSocketServer(int port);
    int initialConfigFile(QString configFileName);
    int sendAgvBasicInformation();
    int sendMessageInfo();
    int sendRobotArmInfo();
    int processClientRequest();
    int sendData(const QByteArray &dataIn);
    int sendOkFrame();
    int sendAbortFrame();
    int receiveData(QByteArray &dataOut);
    void addMsg(int messageLevel,
                 std::string componentName,
                 std::string messageType,
                 int messageCode,
                 int robotId,
                 QString parameter1 = "",
                 int parameter2 = 0,
                 int parameter3 = 0,
                 int parameter4 = 0 );




private:

    bool isInitialOkStatus;

    QTcpSocket *tcpSocket;
    QTcpServer *tcpServer;

    QTimer* timer;
    bool isUseFleet;
    int serverPort;
    QString passPort_authority;//正确密码
    QString passPort_client;//客户传递密码
    QString clientIp;//当前客户ｉｐ
    FleetService *fleetService;
    UserInfo *userInfo;
    QQueue<QString> fleetCommandLog;
    int maxFleetCatchLineForDebug;
    int isSendMessageString;
    int isSendRobotArmInfo;
    int heartBeat;
    int diMonitorIndex;
    int diTrigCount;
    int sendPeriod;//ms
    QByteArray cashFrame;



};

#endif // SOCKETFLEETADAPTER_H
